package cn.byapps.attendance.service.impl;

import java.io.File;
import java.io.FileInputStream;
import java.util.List;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.springframework.stereotype.Service;

import cn.byapps.attendance.dao.StudentDao;
import cn.byapps.attendance.entity.Student;
import cn.byapps.attendance.service.ExcelService;
import core.excel.ImportExcel;

@Service
@Transactional
public class ExcelServiceImpl implements ExcelService {
	@Resource
	private StudentDao studentDao;

	@Override
	public int importStu(File excfile) {

		// 解析Excel表格获取信息
		FileInputStream excfileinput;
		try {
			excfileinput = new FileInputStream(excfile);
			ImportExcel imp = new ImportExcel(excfile.getName(), excfileinput, 0, 0);
			List<Student> stus = imp.getDataList(Student.class, null);
			// 遍历数据
			for (Student s : stus) {
				studentDao.add(s);
			}
			return 1;
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
	}

}
